/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmListaCliente.java
 *
 * Created on 14-oct-2011, 10:05:45
 */
package apiformularios.form;

import api.dom.Utilitaria;
import java.awt.print.PrinterException;
import java.text.MessageFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTable.PrintMode;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;

/**
 *
 * @author Luis
 */
public class FrmListaCliente extends javax.swing.JInternalFrame {

    /** Creates new form FrmListaCliente */
    public FrmListaCliente() {
        initComponents();
        this.setVisible(true);
        ((javax.swing.plaf.basic.BasicInternalFrameUI) this.getUI()).setNorthPane(null);
        Utilitaria.listarClientes((DefaultTableModel) this.jTable2.getModel());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        txthasta = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLabel15 = new javax.swing.JLabel();
        btnBuscar1 = new javax.swing.JButton();
        btnBuscar2 = new javax.swing.JButton();
        txtdesde = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        setMinimumSize(new java.awt.Dimension(24, 32));
        setNormalBounds(new java.awt.Rectangle(0, 0, 650, 570));
        setPreferredSize(new java.awt.Dimension(652, 592));
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jScrollPane2.setMaximumSize(new java.awt.Dimension(580, 570));
        jScrollPane2.setMinimumSize(new java.awt.Dimension(580, 570));

        jTable2.setAutoCreateRowSorter(true);
        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Numero", "Nombre completo", "Direccion", "Telefono", "Dicose", "Rut"
            }
        ));
        jTable2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable2MouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTable2);

        getContentPane().add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 110, 630, 400));

        txthasta.setMaximumSize(new java.awt.Dimension(580, 570));
        txthasta.setMinimumSize(new java.awt.Dimension(580, 570));
        txthasta.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txthastaKeyTyped(evt);
            }
        });
        getContentPane().add(txthasta, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 80, 150, -1));

        jPanel1.setBackground(new java.awt.Color(153, 180, 209));
        jPanel1.setMaximumSize(new java.awt.Dimension(580, 570));
        jPanel1.setMinimumSize(new java.awt.Dimension(580, 570));
        jPanel1.setPreferredSize(new java.awt.Dimension(650, 71));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel15.setBackground(new java.awt.Color(51, 255, 51));
        jLabel15.setFont(new java.awt.Font("Tahoma", 0, 48));
        jLabel15.setText("Lista de clientes");
        jLabel15.setToolTipText("");
        jPanel1.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, -1, 49));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 650, 70));

        btnBuscar1.setText("Listar");
        btnBuscar1.setMaximumSize(new java.awt.Dimension(580, 570));
        btnBuscar1.setMinimumSize(new java.awt.Dimension(580, 570));
        btnBuscar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscar1ActionPerformed(evt);
            }
        });
        getContentPane().add(btnBuscar1, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 520, 90, 40));

        btnBuscar2.setText("Imprimir");
        btnBuscar2.setMaximumSize(new java.awt.Dimension(580, 570));
        btnBuscar2.setMinimumSize(new java.awt.Dimension(580, 570));
        btnBuscar2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscar2ActionPerformed(evt);
            }
        });
        getContentPane().add(btnBuscar2, new org.netbeans.lib.awtextra.AbsoluteConstraints(550, 520, 90, 40));

        txtdesde.setMaximumSize(new java.awt.Dimension(580, 570));
        txtdesde.setMinimumSize(new java.awt.Dimension(580, 570));
        txtdesde.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtdesdeKeyTyped(evt);
            }
        });
        getContentPane().add(txtdesde, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 80, 150, -1));

        jLabel1.setText("Desde Cliente Nro :");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 80, -1, 20));

        jLabel2.setText("Hasta Cliente Nro :");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 80, -1, 20));

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked
    // TODO add your handling code here:
        /*txtNumero.setText(String.valueOf(jTable2.getValueAt(jTable2.getSelectedRow(), 0)));
    txtNombre.setText(String.valueOf(jTable2.getValueAt(jTable2.getSelectedRow(), 1)));
    txtDireccion1.setText(String.valueOf(jTable2.getValueAt(jTable2.getSelectedRow(), 2)));
    txtTelefono.setText(String.valueOf(jTable2.getValueAt(jTable2.getSelectedRow(), 3)));
    txtDicose.setText(String.valueOf(jTable2.getValueAt(jTable2.getSelectedRow(), 4)));
    txtRut.setText(String.valueOf(jTable2.getValueAt(jTable2.getSelectedRow(), 5)));*/
}//GEN-LAST:event_jTable2MouseClicked

private void btnBuscar2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscar2ActionPerformed
    MessageFormat encabezado = new MessageFormat("Listado de Clientes");
    try {
        // TODO add your handling code here:
        
        jTable2.print(PrintMode.FIT_WIDTH, encabezado, null);
        print(null);
    } catch (PrinterException ex) {
        Logger.getLogger(FrmListaCliente.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_btnBuscar2ActionPerformed

private void btnBuscar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscar1ActionPerformed
    // TODO add your handling code here:
    try {
        Utilitaria.listarClientes((DefaultTableModel) this.jTable2.getModel());
        DefaultTableModel modelo1 = (DefaultTableModel) jTable2.getModel();
        int i = jTable2.getRowCount();
        int hasta = Integer.parseInt(txthasta.getText());
        int desde = Integer.parseInt(txtdesde.getText());

        for (int x = 0; x < i; x++) {
            int valordeljtable = Integer.parseInt(String.valueOf(modelo1.getValueAt(x, 0)));
            if (valordeljtable > hasta || valordeljtable < desde) {
                modelo1.removeRow(x);
                x--;
            }
        }
    } catch (ArrayIndexOutOfBoundsException a) {
    }


}//GEN-LAST:event_btnBuscar1ActionPerformed

private void txtdesdeKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtdesdeKeyTyped
    // TODO add your handling code here:
    char caracter = evt.getKeyChar();
    if (((caracter < '0')
            || (caracter > '9'))
            && (caracter != evt.VK_BACK_SPACE)) {
        evt.consume();
    }
}//GEN-LAST:event_txtdesdeKeyTyped

private void txthastaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txthastaKeyTyped
    // TODO add your handling code here:
    char caracter = evt.getKeyChar();
    if (((caracter < '0')
            || (caracter > '9'))
            && (caracter != evt.VK_BACK_SPACE)) {
        evt.consume();
    }
}//GEN-LAST:event_txthastaKeyTyped
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscar1;
    private javax.swing.JButton btnBuscar2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable2;
    private javax.swing.JTextField txtdesde;
    private javax.swing.JTextField txthasta;
    // End of variables declaration//GEN-END:variables
}
